package net.piencak.phonetools.gpscc;

import java.io.IOException;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.StringItem;

public class AboutForm extends Form implements CommandListener {

	private GPSCC app;
	
	public AboutForm(GPSCC app) {
		super("GPS Converter");
		
		this.app = app;

		appendStringItem("GPS Converter", "in handy");
		appendStringItem("Version : ", app.getAppProperty("MIDlet-Version"));
		appendStringItemLink("Author: ", "mirecxp@gmail.com");
		appendStringItemLink("Home: ", "http://code.google.com/p/gps-converter");
		
		addCommand(new Command("EXIT", Command.EXIT, 0));
		addCommand(new Command("<<", Command.SCREEN, 3));
		
		setCommandListener(this);
	}
	
	private void appendStringItem(String label, String text) {
		StringItem stringItem = new StringItem(label, text);
		stringItem.setLayout(Item.LAYOUT_NEWLINE_AFTER);
		append(stringItem);		
	}

	private void appendStringItemLink(String label, String text) {
		StringItem stringItem = new StringItem(label, text, StringItem.HYPERLINK);
		stringItem.setLayout(Item.LAYOUT_NEWLINE_AFTER);
		append(stringItem);		
	}

	public void commandAction(Command com, Displayable d) {
		String label = com.getLabel();

		if ("EXIT".equalsIgnoreCase(label)) {
			app.notifyDestroyed();
		} else if ("<<".equals(label)) {
			app.showConvert();
		}
	}
	
}
